<?php


namespace App\Http\Controllers\Home;


use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Config;

abstract class BaseController extends Controller
{
    /**
     * 默认模版前缀
     * @var string
     */
    protected $templatePrefix = 'home.default.';

    /**
     * 每页条数
     * @var int
     */
    protected $pageSize = 12;

    public function __construct()
    {
        if (!request()->ajax()) {
            $this->withData('templatePrefix', $this->templatePrefix); // 模板名称
            $this->withData('templateName', 'default'); // 模板名称
            $this->withData('stylePath', 'public/home/default'); // 样式路径
        }
        $this->setAllConfig();
    }

    private function setAllConfig()
    {
        $lists = \App\Model\Basic\Config::query()->get();
        foreach ($lists as $k => $config) {
            $value = $config->value;
            if ((int) $config->type === 2) {
                $value = json_decode($config->value, true);
            }
            Config::set($config->key, $value);
        }
    }
}